<?php
/**
 * @property JobGroup   $JobGroup
 * @property JobVersion $JobVersion
 * @property JobAltName $JobAltName
 * @property Description $Description
 * @property JobsTag    $JobsTag
 */
class Job extends AppModel {
  
	var $name = 'Job';
	var $displayField = 'name';
  
  // These must be set so that AppModel::removeBlankOptionalFields()  can do it's job.
  //   (this is inherited from AppModel)
  var $optionalAssocModelsAndFields = array('JobAltName'=>'name', 'Description'=>'content');
  
  // <editor-fold defaultstate="collapsed" desc="validate array">
  var $validate = array(
      
		'name' => array(
        'notempty' => array(
          'rule' => array('notempty'),
          'message' => 'This value cannot be empty.',
          //'allowEmpty' => false,
          //'required' => false,
          //'last' => false, // Stop validation after this rule
          //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        'maxlength' => array(
          'rule' => array('maxlength', 256),
          'message' => 'Maximum length of this field is 256.',
          //'allowEmpty' => false,
          //'required' => false,
          //'last' => false, // Stop validation after this rule
          //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        // Note: we're now tyring to make the pair (job_group_id,name) unique instead.
            //'isUnique' => array(
            //    'rule' => 'isUnique',        
            //    'message' => 'This value has already been taken. Please choose something unique.'
            //)
        'unique' => array(
            //'rule' => array('checkUnique', array('job_group', 'name')),
            'rule' => array('myCheckUnique', array('job_group_id', 'name')),
            'message' => 'This name has already been taken for that Job Group. Please choose something unique.'
        )
		),
    'dir_name' => array(
        'notempty' => array(
          'rule' => array('notempty'),
          'message' => 'This value cannot be empty.',
          //'allowEmpty' => false,
          //'required' => false,
          //'last' => false, // Stop validation after this rule
          //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        'maxlength' => array(
          'rule' => array('maxlength', 256),
          'message' => 'Maximum length of this field is 256.',
          //'allowEmpty' => false,
          //'required' => false,
          //'last' => false, // Stop validation after this rule
          //'on' => 'create', // Limit validation to 'create' or 'update' operations
        )
     ),
	);  // </editor-fold>
  
  // ASSOCIATIONS
  // <editor-fold defaultstate="collapsed" desc="Associations">
	// The Associations below have been created with all possible keys, those that are not needed can be removed

  var $belongsTo = array(
		'JobGroup' => array(
        'className' => 'JobGroup',
        'foreignKey' => 'job_group_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
		),  
	);
  
	var $hasOne = array(
		'Description' => array(
			'className' => 'Description',
			'foreignKey' => 'job_id',
      'dependent'    => true,   // When a job gets deleted, also delete it's Description
                                  //  (be sure the 'cascade' option is set to true in the delete()
                                  //   call [it is by default])
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'JobAltName' => array(
			'className' => 'JobAltName',
			'foreignKey' => 'job_id',
      'dependent'    => true,   // When a job gets deleted, also delete it's Alt Name  
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	); // end hasOne definition
  
  var $hasMany = array(
		'JobVersion' => array(
        'className' => 'JobVersion',
        'foreignKey' => 'job_id',
        'dependent'    => true,   // When a job gets deleted, also delete it's versions
        //'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
		),
      
    // Trying to make the HABTM 'join table' a regular association instead by making it a 'membership' table.
    //      Job hasMany JobsTag
    //      Tag hasMany JobsTag
    //      JobsTag belongsTo Job,Tag
    'JobsTag' => array(
        'className' => 'JobsTag',
        'foreignKey' => 'job_id',
        'dependent'    => true,   // When a job gets deleted, also delete it's tag membership
        //'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
		)
      
	); // end hasMany definition

//	var $hasAndBelongsToMany = array(
//		'Tag' => array(
//			'className' => 'Tag',
//			'joinTable' => 'jobs_tags',
//			'foreignKey' => 'job_id',
//			'associationForeignKey' => 'tag_id',
//			'unique' => true,
//			'conditions' => '',
//			'fields' => '',
//			'order' => '',
//			'limit' => '',
//			'offset' => '',
//			'finderQuery' => '',
//			'deleteQuery' => '',
//			'insertQuery' => ''
//		)
//	);  // </editor-fold>

  
  
} /////////////////////// end class ///////////////////////////////////
